<script>
function delgoods(obj){
if(!confirm('<{t}>确定删除?<{/t}>'))return false;
 for(obj=obj.parentNode; obj.tagName!='TR'; obj=obj.parentNode);
 obj.parentNode.removeChild(obj);
}

function calculate(){
 var iList = document.getElementsByName('aPrice[]');
}
</script>

<form method='post' action='index.php?app=b2c&ctl=admin_order&act=toEdit&finder_id=<{$finder_id}>'  id="orderEdit" extra="subOrder" >
<div class="tableform">
  <h3><{t}>商品信息<{/t}></h3>
 <div class="division" id="orderItemList">
 <{include file="admin/order/detail/edit_items.html"}>
 </div>

 <h3 ><{t}>订单信息<{/t}></h3>
 <div class="division">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <th><{t}>订单号：<{/t}></th>
    <td><{$order.order_id}></td>
    <th><{t}>下单日期：<{/t}></th>
    <td><{$order.createtime|cdate:'SDATE_STIME'}></td>
  </tr>
   <tr>
    <th><{t}>商品总金额：<{/t}></th>
    <td><input id="iditem_amount" TYPE="text" name="cost_item" value="<{$order.cost_item}>" size=10 disabled="disabled"></td>
    <th><{t}>配送方式：<{/t}></th>
    <td><select name=shipping_id><{html_options options=$order.selectDelivery selected=$order.shipping.shipping_id}></select></td>
  </tr>
   <tr>
    <th><{t}>配送费用：<{/t}></th>
    <td><{input id="idcost_freight" class='item itemrow' name="cost_freight" value=$order.shipping.cost_shipping type="unsigned" size=10 readonly=""}></td>
    <th><{t}>支付方式：<{/t}></th>
    <td>
        <select name=payment><{html_options options=$order.selectPayment selected=$order.payinfo.pay_app_id}></select>
        &nbsp;&nbsp;
        <{foreach from=$order.extendCon item=item key=key}>
            <{$item}>&nbsp;&nbsp;
        <{/foreach}></td>
  </tr>
  <tr>
    <th><{t}>保价：<{/t}></th>
    <td><{input id="idcost_protect" class="item itemrow" type="unsigned" name="cost_protect" size=10 value=$order.shipping.cost_protect }><{t}> 是否要保价<{/t}><input id="idis_protect" name="is_protect" type='checkbox' value='true' <{if $order.shipping.is_protect == 'true'}>checked="checked"<{/if}>></td>
    <th><{t}>商品重量：<{/t}></th>
    <td><{input name=weight type="unsigned" readonly="" class=inputstyle size=10 value=$order.weight }></td>
  </tr>
  <{if $site_trigger_tax == 'true'}>
  <tr>
    <th><{t}>支付手续费：<{/t}></th>
    <td><{input id="idcost_payment" class='item itemrow' name=cost_payment type="unsigned" size=10 value=$order.payinfo.cost_payment }></td>
    <th><{t}>发票抬头：<{/t}></th>
    <td><{input id="idtax_company" name="tax_company" value=$order.tax_title}></td>
  </tr>
   <tr>
    <th><{t}>税金：<{/t}></th>
    <td><{input id="idcost_tax" class='item itemrow' name="cost_tax" type="unsigned" size=10 value=$order.cost_tax }><{t}> 是否开发票<{/t}><input id="idis_tax" name="is_tax" type='checkbox' value='true' <{if $order.is_tax == 'true'}>checked="checked"<{/if}>></td>
    <th><{t}>发票内容：<{/t}></th>
    <{if $tax_content}>
    <td><{input type='select' name='tax_content' options=$tax_content  value=$order.tax_content}></td>
    <{else}>
    <td>后台未设置</td>
    <{/if}>
  </tr>
   <tr>
    <th><{t}>促销优惠金额：<{/t}></th>
    <td><input id="idpmt_order" class='item itemrow' name="pmt_order" value="<{$order.pmt_order}>" size=10></td>
    <th><{t}>订单折扣或涨价：<{/t}></th>
    <td><input id="iddiscount" class='item itemrow' name="discount" value="<{$order.discount}>" size=10><br><{t}>要给顾客便宜100元，则输入"-100";要提高订单价格100元，则输入"100".<{/t}>
  </tr>
   <tr>
    <th><{t}>订单总金额：<{/t}></th>
    <td><input id="idtotal_amount" name=total_amount value="<{$order.total_amount}>" disabled="disabled"></td>
    <th><{t}>支付币别：<{/t}></th>
    <td><{if $order.order_id == ''}><{html_options options=$order.curList selected=$order.currency}><{else}><{$order.cur_name}><{if $order.cur_rate != 1}>(<{$order.cur_rate}>)<{/if}><{/if}></td>
</td>
  </tr>
  <{else}>
  <tr>
    <th><{t}>支付手续费：<{/t}></th>
    <td><{input id="idcost_payment" class='item itemrow' name=cost_payment type="unsigned" size=10 value=$order.payinfo.cost_payment }></td>
    <th><{t}>支付币别：<{/t}></th>
    <td><{if $order.order_id == ''}><{html_options options=$order.curList selected=$order.currency}><{else}><{$order.cur_name}><{if $order.cur_rate != 1}>(<{$order.cur_rate}>)<{/if}><{/if}></td>
  </tr>
   <tr>
    <th><{t}>促销优惠金额：<{/t}></th>
    <td><input id="idpmt_order" class='item itemrow' name="pmt_order" value="<{$order.pmt_order}>" size=10></td>
    <th><{t}>订单折扣或涨价：<{/t}></th>
    <td><input id="iddiscount" class='item itemrow' name="discount" value="<{$order.discount}>" size=10><br><{t}>要给顾客便宜100元，则输入"-100";要提高订单价格100元，则输入"100".<{/t}>
  </tr>
   <tr>
    <th><{t}>订单总金额：<{/t}></th>
    <td><input id="idtotal_amount" name=total_amount value="<{$order.total_amount}>" disabled="disabled"></td>

</td>
  </tr>
  <{/if}>
</tr>
   <tr>
    <th><{t}>订单获得积分：<{/t}></th>
    <td><{input id="idtotal_score" class='item itemrow' name=score_g type="unsigned" size=10 value=$order.score_g}></td>
    <th><{t}>该订单已使用积分<{/t}></th>
    <td><input id="score_u" name=score_u value="<{$order.score_u}>" disabled="disabled"></td>
    
    <td><input id="idscore_u" name='score_u' class='item itemrow' value="<{$order.score_u}>" type='hidden'></td>
</td>
  </tr>
</table>
</div>

<h3><{t}>购买人信息<{/t}></h3>
<div class="division">
  <{if $order.order_id == ''}>
  <input TYPE="text" NAME="uname" value='' class=inputstyle size=15>
  <input TYPE="button"  class=inputstyle value="<{t}>导入会员<{/t}>" onClick="seluser(adminForm.uname.value)">
  <input TYPE="button"  class=inputstyle value="<{t}>非会员<{/t}>" onClick="seluser('anonymous')">
  <input TYPE="hidden" name="userid" value="{userid}">
  <{/if}>
 <table width="100%" border="0" cellspacing="0" cellpadding="0">

   <tr>
    <th><{t}>会员用户名：<{/t}></th>
    <td><{$order.member.pam_account.local.login_account}></td>
    <th><{t}>姓名：<{/t}></th>
    <td><{$order.member.contact.name}></td>
  </tr>
   <tr>
    <th><{t}>固定电话：<{/t}></th>
    <td><{$order.member.contact.phone.telephone}></td>
    <th><{t}>Email地址：<{/t}></th>
    <td><{$order.member.pam_account.email.login_account}></td>
  </tr>
  <tr>
    <th><{t}>移动电话：<{/t}></th>
    <td><{$order.member.pam_account.mobile.login_account}></td>
    <th></th>
    <td></td>
  </tr>
   <tr>
    <th><{t}>地区：<{/t}></th>
    <td><{$order.member.contact.area|region}></td>
    <th><{t}>邮政编码：<{/t}></th>
    <td><{$order.member.contact.zipcode}></td>
  </tr>
   <tr>
    <th><{t}>地址：<{/t}></th>
    <td><{$order.member.contact.addr}></td>
    <th></th>
    <td></td>
  </tr>
</table>
</div>


<{if $order.is_delivery == 'Y'}>
 <h3><{t}>收货人信息<{/t}></h3>
 <div class="division" id="order_edit_receiver">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
   <tr>
    <th><em class="red">*</em><{t}>收货人姓名：<{/t}></th>
    <td><{input type="text" NAME="receiver_name" required="true" value=$order.consignee.name }></td>
    <th><{t}>联系手机：<{/t}></th>
    <td><input type="text" NAME="ship_mobile" value="<{$order.consignee.mobile}>" class=inputstyle></td>
  </tr>
   <tr>
    <th><{t}>联系电话：<{/t}></th>
    <td><{input type="order_tel" NAME="ship_tel" class=inputstyle value=$order.consignee.telephone}></td>
    <th><{t}>Email地址：<{/t}></th>
    <td><{if $order.member.contact.email}><{$order.member.contact.email}><{else}><input vtype="email" name="ship_email" value="<{$order.consignee.email}>"/><{/if}></td>
  </tr>
   <tr>
    <th><{t}>送货时间：<{/t}></th>
    <td><input type="text" NAME="ship_time" value="<{$order.consignee.r_time}>" class=inputstyle></td>
    <th><{t}>邮政编码：<{/t}></th>
    <td><{input  NAME="ship_zip"  class=inputstyle value=$order.consignee.zip}></td>
  </tr>
   <tr>
    <th><em class="red">*</em><{t}>收货地区：<{/t}></th>
    <td colspan="3"><{input type="region" name="ship_area" required="true" value=$order.consignee.area app="ectools"}></td>
  </tr>
  <tr>
    <th><em class="red">*</em><{t}>收货地址：<{/t}></th>
    <td colspan="3"><{input type="text" NAME="ship_addr" required="true" class=inputstyle value=$order.consignee.addr}></td>
  </td>
</table>
</div>
</div>
<!--tag_foreign_xaddress-->
 <{/if}>
<!--
<div class="table-action">
    <{button label="提交" type="submit" name='butsubmit'}>
</div>-->


</form>
<script>


	 $ES(".itemrow","moneyItems").each(function(item, index){
		item.addEvent('change',function(e){count_change(this);});
	  });


 function count_change(ipt){
 if(ipt.className.split('_').length > 1){

	   var key=(ipt.className.split('_')[1]);
	   var key = key.split(' ')[0];
	   var item_unit_price = $E('.itemPrice_'+key,'moneyItems').getValue();
	   var item_unit_quantity = $E('.itemNum_'+key,'moneyItems').getValue();

	   var json_arr = '{"unit_price":'+item_unit_price+', "item_quantity":'+item_unit_quantity+'}';
	   new Request({
	   url:'index.php?app=b2c&ctl=admin_order&act=caculate_item_total',method:'post',
			   data:"json_arr="+json_arr+"&operaction=multiple",
		onSuccess:function(response){
		   $E('.itemSub_'+key).setText(response);
		   countF();
		}
	   }).send();
	   //var result=$E('.itemPrice_'+key,'moneyItems').getValue().toFloat()*$E('.itemNum_'+key,'moneyItems').getValue().toInt();
	   //$E('.itemSub_'+key).setText(result);
	  }
	  //countF();

 }

function countF()
{
	var count=0;
	var json_arr='{';
	var index = 0;
	var item_total = 0;
	// item total
	$ES(".itemCount","moneyItems").each(function(item){
	 //count += item.getText().toFloat()*1;
	 	if (index == 0)
	 		json_arr += '"'+index.toString()+'":'+item.getText();
		else
			json_arr += ','+'"'+index.toString()+'":'+item.getText();

		index++;
	});

	json_arr += '}';

   	// subitemtotal.
	new Request({
			url:'index.php?app=b2c&ctl=admin_order&act=caculate_item_total',

			onSuccess:function(response){
				$('iditem_amount').set('value',response);

				json_arr='{';
				json_arr += '"item_subtotal":'+response+'';
				// cost protect fee.
			   	var cost_protect = 0;
				if($('idis_protect').checked){
				    cost_protect = $('idcost_protect').value;
				    json_arr += ',"cost_protect":'+cost_protect;
				}
				// cost tax fee.
				var cost_tax = 0;
				if($('idis_tax')&&$('idis_tax').checked){
				    cost_tax = $('idcost_tax').value;
				    json_arr += ',"cost_tax":'+cost_tax;
				}

				json_arr += ',"cost_freight":'+$('idcost_freight').value;
				json_arr += ',"cost_payment":'+$('idcost_payment').value;
				json_arr += ',"discount":'+$('iddiscount').value;
				json_arr += ',"pmt_order":-'+$('idpmt_order').value;
				/*var count = 0;
				 count = Number($('iditem_amount').value) + cost_protect + $('idcost_freight').value.toFloat() + Number($('idcost_payment').value) + cost_tax + Number($('iddiscount').value) - Number($('idpmt_order').value);*/
				json_arr += '}';

				new Request({
					url:'index.php?app=b2c&ctl=admin_order&act=caculate_item_total',
					onSuccess:function(res)
					{
						$('idtotal_amount').value = res;
					}
				}).post("json_arr="+json_arr+"&operaction=plus");
		}
	}).post("json_arr="+json_arr+"&operaction=plus");
}

 $('idis_protect').addEvent('click',function(e){
  $('idcost_protect').disabled = !$('idis_protect').checked;
  countF();
 });

 if($('idis_tax'))
 $('idis_tax').addEvent('click',function(e){
  $('idcost_tax').disabled = !$('idis_tax').checked;
  countF();

 });

 if($('idis_tax'))
$('idcost_tax').disabled = !$('idis_tax').checked;

 if(!$('idis_protect').checked){
  $('idcost_protect').disabled = true;
 }

</script>
